import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;

public class Setup {
	static User[] USERA;
	static User[] USERB;
	static Item[] ITEMA;

	static String FILE_PATH_USER_A = "../track1/trainIdx1.txt" + ".ser";
	static String FILE_PATH_ITEM_A = "../track1/trainIdx1.txt" + ".ser.item";
	static String FILE_PATH_USER_B;

	static void setup() {
		long time;

		time = System.currentTimeMillis();
		readSerializedUA();
		System.out.println(System.currentTimeMillis() - time);
		System.out.println(USERA[0]);

		time = System.currentTimeMillis();
		readSerializedIA();
		System.out.println(System.currentTimeMillis() - time);
		System.out.println(ITEMA[0]);

		time = System.currentTimeMillis();
		readSerializedUB();
		System.out.println(System.currentTimeMillis() - time);
		System.out.println(USERB[0]);

	}

	static void readSerializedUA() {
		System.out.println("readSerializedUA: " + FILE_PATH_USER_A);

		try {
			InputStream file = new FileInputStream(FILE_PATH_USER_A);
			InputStream buffer = new BufferedInputStream(file);
			ObjectInput input = new ObjectInputStream(buffer);
			try {
				USERA = (User[]) input.readObject();
			} finally {
				input.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
	}

	static void readSerializedUB() {
		System.out.println("readSerializedUB: " + FILE_PATH_USER_B);

		try {
			InputStream file = new FileInputStream(FILE_PATH_USER_B);
			InputStream buffer = new BufferedInputStream(file);
			ObjectInput input = new ObjectInputStream(buffer);
			try {
				USERB = (User[]) input.readObject();
			} finally {
				input.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	static void readSerializedIA() {
		System.out.println("readSerializedIA: " + FILE_PATH_ITEM_A);

		try {
			InputStream file = new FileInputStream(FILE_PATH_ITEM_A);
			InputStream buffer = new BufferedInputStream(file);
			ObjectInput input = new ObjectInputStream(buffer);
			try {
				ITEMA = (Item[]) input.readObject();
			} finally {
				input.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
